function ajax(api, callbackfn) {
	var xhr = new XMLHttpRequest();
	xhr.open('GET', api);
	xhr.send(null);
	//异步操作的数据  不能使用返回值 获取
	//异步的操作 都会等 同步操作做完  以后再执行
	xhr.onload = function() {
		if(xhr.status = 200) {
			//console.log(xhr.responseTex );
			//console.log(JSON.parse(xhr.responseText));
			if(callbackfn) {
				callbackfn(JSON.parse(xhr.responseText))
			}

		}
	}
}

//封装ajaxs请求函数
function ajaxs(api, m, n, ele) {
	ajax(api, function(newP) {
		console.log(newP.data)
		var newPsArr = newP.data.reverse();
		var html = '';
		for(let i = m; i < n; i++) {
			let newPObj = newPsArr[i];
			//	console.log(newPObj)
			html += `
								<li pid="${newPObj.pid}" class="addLi">
									<div class="pprice">
									    ${newPObj.pprice}
									</div>
									<a pid="${newPObj.pid}" href="javascript:;" class="sale-imga click-link">
									    <img src="${newPObj.pimg}" class="pimg"/>
									    
									</a>
									<div class="pname">
										<a pid="${newPObj.pid}" href="javascript:;" class="click-link">
											${newPObj.pname}
										</a>
									</div>
								</li>`
			
		}
		ele.innerHTML = html;
		
		//鼠标滑过图片效果
		var addLis=document.querySelectorAll('.addLi');
		//console.log(addLis)
		addLis.forEach(function(li){
			li.onmouseenter=function(evt){
				//console.log(evt.target);
				//console.log(this)
				//background:rgba(250,250,250,0.7);
				animate(this.firstElementChild,{top:265})
				li.onmouseleave=function(leaveEvt){
					animate(this.firstElementChild,{top:295})
				}
			}
		})
		//鼠标点击图片a标签跳转
		var clickLinks=document.querySelectorAll('.click-link');
		//console.log(clickLinks)
		clickLinks.forEach(function(ele){
			ele.onclick=function(){
				console.log(this)
				let getPid=this.getAttribute('pid');
				this.href=`goods-list.html?pid=${getPid}`
			}
		})
		
	})
} //ajaxs结束